﻿#ifndef __H_TVPLAYER_H__
#define __H_TVPLAYER_H__

#include <QWidget>
#include <QPair>
#include <QQueue>
#include <QVariant>
#include <QImage>
#include <atomic>
#include <QMutex>

#include "TVPlayer_global.h"


class QPaintEvent;
class QPainter;
class QTimeLine;
class StreamDecodec;
class StreamEncodec;
class QAudioOutput;
//class QAudioDeviceInfo;
class QIODevice;

class TVPLAYER_EXPORT TVPlayer
    : public QWidget
{
    Q_OBJECT
public:
    TVPlayer(QWidget* parent = nullptr);
    virtual ~TVPlayer();

    QString getUrl() const { return m_strUrl; }
    void setUrl(QString val);
    void play();

    void stop();

protected:
    void init();

    virtual void paintEvent(QPaintEvent *event);

    void paintBlankFrame(QPainter* painter);

    void timerEvent(QTimerEvent* event);

private Q_SLOTS:

    void slotStreamRecvView(QVariant view);
    void slotStreamAudio(QVariant audio);
    void slotStreamTimeout();

private:
    QString m_strUrl;
    // 解码
    StreamDecodec* m_pDecodec;
    // 编码
    StreamEncodec* m_pEncodec;
    // 视频流
    QQueue<QVariant> m_queueStreamView;
    // 音频流
    QQueue<QVariant> m_queueStreamAudio;
    // 画面计时器
    QTimeLine* m_pTimeLine;
    // 视频流是否超时
    bool m_bStreamTimeout;
    // 是否正在播放
    bool m_bVideoPlaying;
    //当前绘制的画面
    QImage m_currentImage;
    // 音频播放
    QAudioOutput* m_pAudioOutPut;
    // 播放设备
    // QAudioDeviceInfo* m_pDeviceInfo;

    QIODevice* m_AduioIO;
    //QMutex m_mutex;

    int m_nTimerId;
};



#endif // __H_TVPLAYER_H__
